package adata;

import java.util.LinkedList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.RowSet;

import model.ApplicationModel;


import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;
import forms.ApplicantForm;
import forms.Degree;

public class DegreeLocationPageAction extends Action{
	
	public ActionForward execute(ActionMapping mapping, ActionForm form, 
		    HttpServletRequest request, HttpServletResponse response) 
		    throws DbException{
		
		
		
		//request.setAttribute("locationName", request.getParameter("locationName"));
		String currentLocationName = request.getParameter("locationName");
		
		/*
		Integer count = ApplicationModel.getUnivCount(ad);
		request.setAttribute("count", count);
		
		request.setAttribute("LocationName", currentLocationName);
		*/
			
		RowSet crsUniversities = ApplicationModel.getLocationsUniversities(currentLocationName);
		RowSet crsCountUniv = ApplicationModel.getUnivCountOfLocation(currentLocationName);
		
		// Store the RowSet in the request scope
		request.setAttribute("crsUniversities", crsUniversities);
		request.setAttribute("crsCountUniv", crsCountUniv);
		
		
		
		//////////////////////////////////////////////////////////////////////////////////////
		
		
		
		
		List<Degree> theDegreeArray;
		if (request.getSession().getAttribute("TheSessionDegreeArray") != null)
		{
			// retrieve list from session attribute if it exists
			theDegreeArray = (LinkedList<Degree>) request.getSession().getAttribute("TheSessionDegreeArray");
		}
		else
		{
			// create the list otherwise
			theDegreeArray = new LinkedList<Degree>();
		}
			
		theDegreeArray.add (new Degree());
		Integer currentCount = (Integer)(request.getSession().getAttribute("SessionCounter"));
		theDegreeArray.get(currentCount).setLocation (currentLocationName.toString().replace('_', ' '));
		request.getSession().setAttribute ("TheSessionDegreeArray", theDegreeArray);
		
		return mapping.findForward("success");
		
	}
}
